package org.chengn.level_middle.context447;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: Context447
 * @Author ChengN
 * @Package org.chengn.level_middle.context447
 * @Date 2024/1/8 0:33
 * @description: 回旋镖的数量
 */
public class Context447 {
    public int numberOfBoomerangs(int[][] points) {
        int res = 0;
        if (points.length < 3) return 0;
        for (int i = 0; i < points.length; ++i) {
            Map<Integer, Integer> map = new HashMap<>();
            for (int j = 0; j < points.length; ++j) {
                if (j == i) continue;
                int dist = pow(points[i], points[j]);
                int num = map.getOrDefault(dist, 0);
                res += num * 2;
                map.put(dist, num + 1);
            }
        }
        return res;
    }
    int pow(int[] a, int[] b) {
        return (a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]);
    }
}
